Adding release flag to cargo test
authorPrabhjyot Singh Sodhi <prabhjyotsingh95@gmail.com>
Tue, 24 Mar 2015 20:43:30 +0000 (02:13 +0530)
committerPrabhjyot Singh Sodhi <prabhjyotsingh95@gmail.com>
Wed, 15 Apr 2015 22:40:47 +0000 (04:10 +0530)
src/bin/test.rs
tests/test_cargo_test.rs

index 1b09e6d2ce0d644845b9957d9882493dbe06d265..85251624b87c61df6a6f812fa6183839db2afe15 100644 (file)
@@ -15,6 +15,7 @@ struct Options {
     flag_package: Option<String>,
     flag_target: Option<String>,
     flag_verbose: bool,
+    flag_release: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -30,6 +31,7 @@ Options:
     --no-run                 Compile, but don't run tests
     -p SPEC, --package SPEC  Package to run tests for
     -j N, --jobs N           The number of jobs to run in parallel
+    --release                Build artifacts in release mode, with optimizations
     --features FEATURES      Space-separated list of features to also build
     --no-default-features    Do not build the `default` feature
     --target TRIPLE          Build for the target triple
@@ -72,7 +74,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             no_default_features: options.flag_no_default_features,
             spec: options.flag_package.as_ref().map(|s| &s[..]),
             exec_engine: None,
-            release: false,
+            release: options.flag_release,
             mode: ops::CompileMode::Test,
             filter: if tests.is_empty() && bins.is_empty() {
                 ops::CompileFilter::Everything
index 6c08c73aea7f7ebbbc9badb828f239e4a5ef5f94..0ee882e1cb7a2b37743adc94d4d9b95a0ca19d1e 100644 (file)
@@ -46,6 +46,54 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
         RUNNING)));
 });
 
+test!(cargo_test_release {
+    let p = project("foo")
+        .file("src/lib.rs", r#"
+            extern crate bar as the_bar;
+
+            pub fn bar() { the_bar::baz(); }
+
+            #[test]
+            fn foo() { bar(); }
+        "#)
+        .file("tests/test.rs", r#"
+            extern crate foo as the_foo;
+
+            #[test]
+            fn foo() { the_foo::bar(); }
+        "#)
+        .file("bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            name = "bar"
+            crate_type = ["dylib"]
+        "#)
+        .file("bar/src/lib.rs", "
+             pub fn baz() {}
+        ");
+
+    assert_that(p.cargo_process("test").arg("-v").arg("--release"),
+                execs().with_stdout(format!("\
+{compiling} bar v0.0.1 ({dir})
+{running} [..] -C opt-level=3 [..]
+{compiling} foo v0.0.1 ({dir})
+{running} [..] -C opt-level=3 [..]
+{running} [..] -C opt-level=3 [..]
+{running} `[..]target[..]foo-[..]`
+
+running 1 test
+test test_hello ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+",
+        compiling = COMPILING, dir = p.url(), running = RUNNING)));
+});
+
 test!(cargo_test_verbose {
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))